<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/jq.md5.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #datalist tr td{text-align:center;}
        </style>
    </head>
    <body>
        <div id="panel">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr class="trhd">
                    <td colspan="2"><h3 class="s1">管理员信息管理</h3></td>
                    <td width="8%">&nbsp;</td>
                    <td width="7%">&nbsp;</td>
                    <td width="40%">&nbsp;</td>
                </tr>
                <tr>
                    <td width="12%">角色类型：</td>
                    <td width="22%">
                        <select id="roleid" name="roleid" style="width:150px;"></select>
                    </td>
                    <td><span id="tip_num"></span></td>
                    <td></td>
                    <td class="r"><input onclick="MOP.list(1, 0);" name="submitBtn" type="button" class="button small orange" id="submitBtn" value="Φ 查询"></td>
                </tr>
            </table>
        </div>


        <div class="databox">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th width="5%">MGRID</th>
                    <th width="23%">账号名称</th>
                    <th width="45%">角色类别</th>
                    <th> 操作</th>
                </tr>
                <tbody class="tbchg" id="datalist"></tbody>
            </table>
        </div>
        <div class="page" id="page"></div>

        <div style="display:block;clear:both;width:98%;height:50px;">&nbsp;</div>





        <!-- 数据处理 -->
        <script id="listTpl" type="text/html">
            {%  for(var k in list){ var e = list[k]; %}
        <tr>
            <td>{%=e.mgrid%}</td>
            <td>{%=e.mgrname%}</td>
            <td>{%=e.rolename%}</td>
            <td>
                {% if(e.mgrid>1){ %}
                <a  href="#a" onclick="MOP.modrole('{%=e.mgrid%}','{%=e.roleid%}');">更改角色</a> | 
                <a  href="#a" onclick="MOP.del('{%=e.mgrid%}');">删除</a> | 
                <a href="#a" onclick="MOP.modkey('{%=e.mgrid%}','{%=e.mgrname%}');">更改密码</a> | 
                <a href="#a" onclick="MOP.modcids('{%=e.mgrid%}','{%=e.mgrname%}');">栏目权限</a>
                {% }else{ %}
                -
                {% } %}
            </td>
        </tr>
        {% } %}
    </script>

    <script type="text/javascript">
        var $lsout = $('#datalist');
        var par={};
        var MOP={
            list:function(pgno,r){
                var ls =20;
                var step =10;
                var cr = (ls * ( pgno - 1 ));

                par.roleid=$('#roleid').val();
                par.rownum=r;
                par.crow=cr;
                par.currpage=pgno;
                par.ls=ls;
                TxBox.wait();
                $.ajax({type:"GET",cache:false,async:true,url:'../app/admin/list_factor.shtm',dataType:"json",data:$.param(par),
                    success:function(d){
                        var x = d;
                        rn=x.rownum;
                        $('#tip_num').text('查到 '+rn+' 条信息');
                        if(rn>0){
                            ut.outpage(pgno, rn, 'MOP.list','page', ls, step);
                            $lsout.html(template.render('listTpl',x));
                        }else{
                            $lsout.html('<tr><td colspan="4">暂无数据.</td></tr>');
                            $('#page').html('');
                        }
                    },
                    complete:function(){TxBox.hide();},
                    error:function(){}
                });
            },
            del:function(id){
                if(!window.confirm("确定删除么?执行后不可恢复. 注意:执行该操作需要管理员权限."))return;
                $.get('../app/admin/delete_mgr.shtm?t='+ut.r(), "mgrid="+id, function(x){
                    var r = $.trim(x);
                    if(r=='ok'){
                        ut.m('删除成功.');
                        MOP.list(par.currpage,0);
                    }else{
                        ut.m('删除失败. '+r);
                    }
                });
            },
            modkey:function(id,n){
                var k = window.prompt('修改 <'+n+'>的密码为:','');
                if(va.isnull(k)){return;}
                var p={mgrkey:$.md5($.trim(k)),mgrid:id};
                var u = $.param(p);
                $.get('../app/admin/reset_mgr_key.shtm',u,function(x){
                    var r = $.trim(x);
                    if(r=='ok'){
                        ut.m('成功更新管理员密码.');
                    }else{
                        ut.m('更改管理员密码失败.'+r);
                    }
                });
            },
            modrole:function(id,roleid){
                TxBox.winpop(420, 150, '更新角色授权', 'mgr_edit_role_pop.html?mgrid='+id+'&roleid='+roleid+'&t='+ut.r()+'&page='+par.currpage);
            },
            modcids:function(id,na){
                ut.reload('mgr_edit_cids.html?mgrid='+id+'&t='+ut.r()+'&page='+par.currpage+'&mgrname='+ut.enc(na));
            }
        };
        MOP.list(1, 0);
        MGR.loadRoleSel(null);
    </script>
</body>
</html>
